// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-8-13

#include "stdafx.h"
#include ".\settingpagectrl.h"


// class CJoySettingPageContainer

IMPLEMENT_DYNAMIC(CJoySettingPageContainer, CJoyPageContainer)

//##ModelId=44C4B5DC037D
CJoySettingPageContainer::CJoySettingPageContainer(CJoySettingPageCtrl* pageCtrl)
{
    m_pageCtrl = pageCtrl;
    m_cornerColor.SetValue(0x00000000);
    m_frameColor.SetValue(0x00000000);
    m_cornerSize = 0;
}

//##ModelId=44C4B5DC037F
CJoySettingPageContainer::~CJoySettingPageContainer(void)
{
}

BEGIN_MESSAGE_MAP(CJoySettingPageContainer, CJoyPageContainer)
END_MESSAGE_MAP()

//##ModelId=44C4B5DC0370
void CJoySettingPageContainer::CM_LoadSkin(CJoyXmlElement* pSkinElem)
{
    __super::CM_LoadSkin(pSkinElem);

    m_cornerColor.SetValue(pSkinElem->ReadIntX("corner_color", m_cornerColor.GetValue()));
    m_frameColor.SetValue(pSkinElem->ReadIntX("frame_color", m_frameColor.GetValue()));

    m_cornerSize = (int)pSkinElem->ReadIntD("corner_size", m_cornerSize);
}

//##ModelId=44C4B5DC037A
void CJoySettingPageContainer::CM_Draw(Graphics& graph)
{
    __super::CM_Draw(graph);

    CJoyPageTabSet* tabSet = m_pageCtrl->m_tabSet;

    int w = m_area.Width();
    int h = m_area.Height();
    int wc = w-m_cornerSize;
    int hc = h-m_cornerSize;

    CRect tabArea(0, 0, 0, 0);
    CJoyCheckBox* selTab = m_pageCtrl->m_tabGroup.GetSel();
    if(selTab != NULL)
    {
        tabArea = selTab->GetArea();
    }

    Point topLeft[3] = 
    {
        Point( 0, 0 ),
        Point( 0, m_cornerSize ),
        Point( m_cornerSize, 0 ),
    };
    Point topRight[3] = 
    {
        Point( wc, 0 ),
        Point( w, 0 ),
        Point( w, m_cornerSize ),
    };
    Point bottomLeft[3] = 
    {
        Point( 0, hc-1 ),
        Point( 0, h ),
        Point( m_cornerSize, h ),
    };
    Point bottomRight[3] = 
    {
        Point( w, hc-1 ),
        Point( w, h ),
        Point( wc-1, h ),
    };

    SolidBrush cornerBrush(m_cornerColor);
    Pen framePen(m_frameColor);

    switch(tabSet->GetAlign())
    {
    case AT_Left:
        if(m_pageCtrl->m_tabStart < 0)
        {
            graph.FillPolygon(&cornerBrush, topLeft, 3);
        }
        else
        {
            graph.FillPolygon(&cornerBrush, bottomLeft, 3);
        }
        graph.FillPolygon(&cornerBrush, topRight, 3);
        graph.FillPolygon(&cornerBrush, bottomRight, 3);
        break;
    case AT_Right:
        if(m_pageCtrl->m_tabStart < 0)
        {
            graph.FillPolygon(&cornerBrush, topRight, 3);
        }
        else
        {
            graph.FillPolygon(&cornerBrush, bottomRight, 3);
        }
        graph.FillPolygon(&cornerBrush, bottomLeft, 3);
        graph.FillPolygon(&cornerBrush, topLeft, 3);
        break;
    case AT_Bottom:
        if(m_pageCtrl->m_tabStart < 0)
        {
            graph.FillPolygon(&cornerBrush, bottomLeft, 3);
        }
        else
        {
            graph.FillPolygon(&cornerBrush, bottomRight, 3);
        }
        graph.FillPolygon(&cornerBrush, topRight, 3);
        graph.FillPolygon(&cornerBrush, topLeft, 3);
        break;
    case AT_Top:
    default:
        if(m_pageCtrl->m_tabStart < 0)
        {
            graph.FillPolygon(&cornerBrush, topLeft, 3);
            graph.DrawLine(&framePen, m_cornerSize+1, 1, tabArea.left-1, 1);
            graph.DrawLine(&framePen, tabArea.right, 1, w, 1);
            graph.DrawLine(&framePen, m_cornerSize, 2, tabArea.left-1, 2);
            graph.DrawLine(&framePen, tabArea.right, 2, w, 2);
        }
        else
        {
            graph.FillPolygon(&cornerBrush, topRight, 3);
            graph.DrawLine(&framePen, 0, 1, tabArea.left, 1);
            graph.DrawLine(&framePen, tabArea.right, 1, w-m_cornerSize-1, 1);
            graph.DrawLine(&framePen, 0, 2, tabArea.left, 2);
            graph.DrawLine(&framePen, tabArea.right, 1, w-m_cornerSize, 2);
        }
        graph.FillPolygon(&cornerBrush, bottomLeft, 3);
        graph.FillPolygon(&cornerBrush, bottomRight, 3);
        break;
    }

    //if((tabSet->GetAlign() != AT_Top
    //Point 
}

IMPLEMENT_DYNAMIC(CJoySettingPageCtrl, CJoyPageCtrl)

//##ModelId=44C4B5DC038E
CJoySettingPageCtrl::CJoySettingPageCtrl(void)
{
}

//##ModelId=44C4B5DC039A
CJoySettingPageCtrl::~CJoySettingPageCtrl(void)
{
}

//##ModelId=44C4B5DC038C
CJoyPageContainer* CJoySettingPageCtrl::CreateContainer()
{
    return new CJoySettingPageContainer(this);
}

BEGIN_MESSAGE_MAP(CJoySettingPageCtrl, CJoyPageCtrl)
END_MESSAGE_MAP()
